package com.wch.SpringBootTestDemo.jwt;

import java.text.SimpleDateFormat;
import java.util.Date;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

public class ParseJwtTest3 {
	public static void main(String[] args) {
		String compactJws = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4ODgiLCJzdWIiOiLlsI_nmb0iLCJpYXQiOjE1NTcwMzczMjksImV4cCI6MTU1NzAzNzM4OSwicm9sZXMiOiJhZG1pbiIsInVzIjoiZnpsIiwibG9nbyI6ImxvZ28ucG5nIn0.Qagbh7HIl2sqOLK6uia0FmSTdtVyuS8_XLerfGr2V_w";
		
		Claims claims = Jwts.parser().setSigningKey("itcast").parseClaimsJws(compactJws).getBody();
		System.out.println("id="+claims.getId());
		System.out.println("subject="+claims.getSubject());
		System.out.println("roles="+claims.get("roles"));
		System.out.println("us="+claims.get("us"));
		System.out.println("logo="+claims.get("logo"));
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		System.out.println("签发时间="+sdf.format(claims.getIssuedAt()));
		System.out.println("过期时间="+sdf.format(claims.getExpiration()));
		System.out.println("当前时间="+sdf.format(new Date()));
	}
}
